package com.rowenci.iot_agriculture.mapper;

import com.rowenci.iot_agriculture.bean.Greenhouse;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface GreenhouseDao extends JpaRepository<Greenhouse, Integer> {

    Greenhouse findByNumber(Integer number);

    @Transactional
    @Modifying
    @Query(value = "update Greenhouse greenhouse set greenhouse.illuminance = ?2 where greenhouse.id = ?1 ")
    void updateIlluminanceByHouse_id(Integer house_id, Integer illuminance);

    @Transactional
    @Modifying
    @Query(value = "update Greenhouse greenhouse set greenhouse.tempature = ?2 where greenhouse.id = ?1 ")
    void updateTempatureByHouse_id(Integer house_id, Integer tempature);

    @Transactional
    @Modifying
    @Query(value = "update Greenhouse greenhouse set greenhouse.humidity = ?2 where greenhouse.id = ?1 ")
    void updateHumidityByHouse_id(Integer house_id, Integer humidity);

    @Transactional
    @Modifying
    @Query(value = "update Greenhouse greenhouse set greenhouse.vegetable = ?2 where greenhouse.id = ?1 ")
    void updateVegetableByHouse_id(Integer house_id, String vegetable);

}
